<?php
$total_sale = 0;
$total_cost = 0;
$total_profit = 0;
?>
<div class="request">
	<h1>請求</h1>
	<div class="table">
		<table class="request_table">
			<thead>
				<tr>
					<th>請求日</th>
					<th>クライアント</th>
					<th>ブロガー</th>
					<th>事務所</th>
					<th>Sale</th>
					<th>Cost</th>
					<th>利益</th>
					<th>担当者</th>
				</tr>
			</thead>
			<tbody>
			<?php foreach ($products as $product): ?>
				<tr>
					<th><?php echo $product->getClient_request_date()?></th>
					<th><?php echo $product->getClient()?></th>
					<th><?php echo $product->getBlogger()?></th>
					<th><?php echo $product->getAgent()?></th>
					<?php
					$sale = $product->getSale();
					$cost = $product->getCost();
					$profit = $sale-$cost;

					$total_cost += $cost;
					$total_sale += $sale;
					$total_profit += $profit;
					?>
					<th><?php echo number_format($sale)?>円</th>
					<th><?php echo number_format($cost)?>円</th>
					<th><?php echo number_format($profit)?>円</th>
					<th><?php echo $product->getUser()?></th>
				</tr>
				<?php endforeach; ?>
				<tr class="total">
					<th>合計</th>
					<th></th>
					<th></th>
					<th></th>
					<th><?php echo number_format($total_sale)?>円</th>
					<th><?php echo number_format($total_cost)?>円</th>
					<th><?php echo number_format($total_profit)?>円</th>
					<th></th>
				</tr>
			</tbody>
		</table>
	</div>
	<script type="text/javascript">
		$(function(){
			
			$(".month_option select").change(function(){
				$("#month_select").submit();
			});

		});
	</script>
	<div class="month_option">
		<form id="month_select"
			action="<?php echo url_for("product/request")?>" method="post">
			<select id="month" name="month">
			<?php foreach ($dates as $date):?>
				<option value="<?php echo $date?>"
				<?php if(isset($rMonth) && strcmp($rMonth, $date) == 0) echo "selected='selected'";?>>
					<?php echo $date?>
				</option>
				<?php endforeach;?>
			</select>
		</form>
	</div>
</div>
